require('./PageMaintain.styl');

const reactMixin = require('react-mixin');
const Actions = require('./actions');
const Store = require('./store');
const GirdView = require('components/girdview');
import { Control } from 'react-keeper';
import Panel from 'components/panel'
import Menu from 'components/menu'
var paths = [{ path: "maintenance", title: "维护支持", id: 'index0', tabTitles: "维护审批 维护记录" }];
const ui = require('clientConfig/util/jsapi/ui');
class Maintain extends React.Component {

    constructor(props) {
        super(props);
        this.state = {
        };
        this.action = [
            {
                content: '故障上报',
                icon: "maintenance/faultReporting.svg",
                path: "/home/maintenance/faultreport"
            },
            {
                content: '故障处理',
                icon: "maintenance/faultReporting.svg",
                path: "/home/maintenance/faulthandle"
            }, {
                content: '维护安排',
                icon: "maintenance/faultReporting.svg",
                path: "/home/maintenance/faultarrange"
            },
            {
                content: '维护反馈',
                icon: "maintenance/faultReporting.svg",
                path: "/home/maintenance/faultfeedback"
            }
        ];
        if (Control.state){
            if(Control.state.origin_title=="维护进度"){
                this.activenum = 1; 
                paths = [{ path: "maintenance", title: "维护支持", id: 'index0', tabTitles: "维护记录" }];
            }              
        }else{
            this.activenum = 0;
            paths = [{ path: "maintenance", title: "维护支持", id: 'index0', tabTitles: "维护审批 维护记录" }];           
        }  
        this.handlePlusClick = this.handlePlusClick.bind(this);
    }
    handlePlusClick() {
        this.setState({
            show: true,
        })
    }

    render() {
        let girdItems = [{ title: "待我审批的", hashPath: "/home/maintenance/pending", src: "pending", homesvg: 'workplan0_svg1' }, { title: "我发起的", hashPath: "/home/maintenance/sponsored", src: "sponsored", homesvg: "workplan0_svg2" }, { title: "抄送我的", hashPath: "/home/maintenance/copy", src: "copy", homesvg: "workplan0_svg3" },
        { title: "变更申请", hashPath: "/home/maintenance/changereq", src: "changereq", homesvg: "workplan0_svg4" }, { title: "变更记录", hashPath: "/home/maintenance/changerecord", src: "changerecord", homesvg: "workplan0_svg5" }];
        let pro_girdItems = [{ title: "维护报表", hashPath: "/home/maintenance/maintaintable", src: "pending", homesvg: 'maintenance1_svg1' }];
        return (
            <div className="maintain">
                {paths.map((item, index) => {
                    const ContentSvg = require(`images/svg/mangement/${item.path}.svg`);
                    return (
                        <Panel
                            title={item.title}
                            Key={item.path}
                            active
                            tabTitles={item.tabTitles}
                            cbPlus={this.handlePlusClick}>
                            <ContentSvg className="content-svg"/>
                            {!Control.state && <GirdView girdItems={girdItems} path={item.path} />}
                            <GirdView girdItems={pro_girdItems} path={item.path} />
                        </Panel>
                    );
                })
                }
                {!window.isBp ? <Menu item={this.action} show={this.state.show} /> : ''}
            </div>
        );
    }

    componentWillMount() {
        ui.setTitle({ title: "IT项目管理信息系统" });
    }

    componentDidMount() {
    }

    componentWillReceiveProps(nextProps) {
    }

    shouldComponentUpdate(nextProps, nextState) {
        return true;
    }

    componentWillUpdate(nextProps, nextState) {
    }

    componentDidUpdate(prevProps, prevState) {
    }

    componentWillUnmount() {
    }
}

reactMixin.onClass(Maintain, Reflux.connect(Store, 'Maintain'));

module.exports = Maintain;
